package object;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Tour 
{
	public enum TourType
	{
		UNKNOWN,
		CHEAP,
		USUAL,
		EXPENSIVE,
		HOT
	}
	
	private int id;
	private TourType type;
	private String client;
	private String hotel;
	private Date date;
	
	private boolean isCorrect;
	private final int COUNT_OF_FIELDS = 4;
	
	public Tour()
	{
		isCorrect = true;
	}
	
	public void fillData(String data, int id)
	{
		String[] fields = data.split("\t");
		
		if (fields.length == COUNT_OF_FIELDS)
		{
			setId(id);
			setType(fields[0]);
			setClient(fields[1]);
			setHotel(fields[2]);
			setDate(fields[3]);
		}
		else
		{
			this.isCorrect = false;
		}
	}
	
	@Override
	public String toString()
	{
		SimpleDateFormat formater = new SimpleDateFormat("yyyy.MM.dd");
		return "Tour " + id + " [" + type + " " + client + " " + hotel + " " + formater.format(date) + "]";
	}

	public boolean isCorrect() 
	{
		return isCorrect;
	}

	public void setIsCorrect(boolean isCorrect) 
	{
		this.isCorrect = isCorrect;
	}

	public int getId() 
	{
		return id;
	}
	
	public void setId(int id) 
	{
		this.id = id;
	}
	
	public TourType getType() 
	{
		return type;
	}
	
	public void setType(String type) 
	{
		try 
		{
			this.type = TourType.valueOf(type);                    
		}
		catch (Exception e)
		{
			this.type = TourType.UNKNOWN;
		}
	}
	
	public String getClient() 
	{
		return client;
	}
	
	public void setClient(String client) 
	{
		this.client = client;
	}
	
	public String getHotel() 
	{
		return hotel;
	}
	
	public void setHotel(String hotel) 
	{
		this.hotel = hotel;
	}
	
	public Date getDate() 
	{
		return date;
	}
	
	public void setDate(String date) 
	{
        try
        {
        	SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
        	format.setLenient(false);
        	
        	this.date = format.parse(date);
        } 
        catch (ParseException e) 
        {
        	this.isCorrect = false;
        }
	}
}
